import request from '@/utils/request.js'

// 获取文章详情
const getArticleDetailAPI = ({ id }) => request({
  url: `/v1_0/articles/${id}`
})

// 关注作者
const followAuthorAPI = ({ target }) => request({
  url: '/v1_0/user/followings',
  method: 'POST',
  data: {
    target
  }
})
// 取消关注
const unfollowAuthorAPI = ({ id }) => request({
  method: 'DELETE',
  url: `/v1_0/user/followings/${id}`
})

// 喜欢文章
const likeArticleAPI = ({ target }) => request({
  method: 'POST',
  url: '/v1_0/article/likings',
  data: {
    target
  }
})
// 取消喜欢文章
const unlikeArticleAPI = ({ id }) => request({
  method: 'DELETE',
  url: `/v1_0/article/likings/${id}`
})

// 获取评论
const getCommentListAPI = ({ type, source, offset, limit }) => request({
  url: '/v1_0/comments',
  params: {
    type: 'a',
    source,
    offset,
    limit
  }
})

// 评论点赞
const commentLikeAPI = ({ target }) => request({
  method: 'POST',
  url: '/v1_0/comment/likings',
  data: {
    target
  }
})
// 评论取消点赞
const uncommentLikeAPI = ({ id }) => request({
  method: 'DELETE',
  url: `/v1_0/comment/likings/${id}`
})
// 发布评论
const postCommentAPI = ({ target, content }) => request({
  method: 'POST',
  url: '/v1_0/comments',
  data: {
    target,
    content
  }
})
export {
  getArticleDetailAPI,
  followAuthorAPI,
  unfollowAuthorAPI,
  likeArticleAPI,
  unlikeArticleAPI,
  getCommentListAPI,
  commentLikeAPI,
  uncommentLikeAPI,
  postCommentAPI
}
